package com.yisingle.study.map.one.utils;

import com.yisingle.study.map.one.data.CarPositionData;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

/**
 * @author jikun
 *         Created by jikun on 2018/3/19.
 */

public class NearbyCarUtils {

    public static List<CarPositionData> getNearByCar(double currentlatitude, double currentlongitude) {

        List<CarPositionData> list = new ArrayList<>();
        for (int i = 0; i < 15; i++) {

            double random = Math.random() - 0.5;
            double random1 = Math.random() - 0.5;


            double nowlatitude = formatDouble2(currentlatitude + random * 0.02, 6);
            double nowlongitude = formatDouble2(currentlongitude + random1 * 0.02, 6);

            float bearing = (float) formatDouble2(Math.random() * 360, 0);
            if (bearing <= 0 || bearing >= 360) {
                bearing = 0;
            }
            list.add(new CarPositionData(nowlatitude, nowlongitude, bearing));
        }
        return list;
    }

    public static double formatDouble2(double d, int point) {


        // 新方法，如果不需要四舍五入，可以使用RoundingMode.DOWN
        BigDecimal bg = new BigDecimal(d).setScale(point, RoundingMode.UP);


        return bg.doubleValue();
    }

}
